using System;
using System.Data.Entity.ModelConfiguration.Configuration;

namespace MetadataBasedConfig.POCO
{
    public class LoginHistoryMapping: ModelMapping<LoginHistory>, IMapping
    {
        public LoginHistoryMapping()
            : base(ModelMapping.EntityTableNameMappingStrategy.Value)
        {
            var columnNameMappingStrategy = ColumnNameMappingStrategy.Value;
            Property(e => e.ID).HasColumnName(columnNameMappingStrategy.To("ID"));
            HasRequired(e => e.User).WithMany().Map(config => config.MapKey(columnNameMappingStrategy.To("UserId")));//todo need a AddSuffixMappingStrategy
            Property(e => e.Successed).HasColumnName(columnNameMappingStrategy.To("Successed"));
            Property(e => e.LoginDate).HasColumnName(columnNameMappingStrategy.To("LoginDate"));
            Property(e => e.IP).HasColumnName(columnNameMappingStrategy.To("IP")).HasMaxLength(15).IsRequired();
            Property(e => e.Agent).HasColumnName(columnNameMappingStrategy.To("Agent")).HasMaxLength(50).IsRequired();
        }

        public void RegistTo(ConfigurationRegistrar configurationRegistrar)
        {
            configurationRegistrar.Add(this);
        }
    }
}